<?php
error_reporting(E_ALL ^ E_NOTICE);

set_time_limit(0);
date_default_timezone_set("PRC"); //timezone
$db1=mysql_connect("localhost","root","root"); 
mysql_select_db('faithwar',$db1); 

$db2=mysql_connect('192.168.0.17','root','root'); 
mysql_select_db('faithwar',$db2); 

#$dateTime = date("Y-m-d",strtotime("-1 day"));
$dateTime = date("Y-m-d");

    $deviceid_query = mysql_query("select deviceid,crystal,TcRechargeNum,TcUsedNum from tbheartbeat_last_temp ",$db2); //where date = '$dateTime'


while($deviceid = mysql_fetch_array($deviceid_query))
{

     $sql1 = "UPDATE  faithwar_query_temp SET TcInventoryNum= '$deviceid[crystal]' WHERE deviceid= '$deviceid[deviceid]'";
     $sql2 = "UPDATE  faithwar_query_temp SET TcRechargeNum= '$deviceid[TcRechargeNum]' WHERE deviceid= '$deviceid[deviceid]'";
     $sql3 = "UPDATE  faithwar_query_temp SET TcUsedNum= '$deviceid[TcUsedNum]' WHERE deviceid= '$deviceid[deviceid]'";
     
   if(mysql_query($sql1,$db1)){
    echo "1 update is ok!";
} else {
    echo "failed".mysql_error();
}   

  if(mysql_query($sql2,$db1)){
    echo "2 update is ok!";
} else {
    echo "failed".mysql_error();
}
  if(mysql_query($sql3,$db1)){
    echo "3 update is ok!";
} else {
    echo "failed".mysql_error();
}

}

mysql_close($db1);
mysql_close($db2);
?>